package test;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

class User implements Comparable<User> {
	private int age;

	public User(int age) {
		this.age = age;
	}

	public int getAge() {
		return age;
	}

	@Override
	public int compareTo(User o) {

		return age - o.age;
	}

	@Override
	public String toString() {
		return "User [age=" + age + "]";
	}

}

class StuUser extends User {
	private String no;

	public StuUser(int age, String no) {
		super(age);
		this.no = no;
	}

	public String getNo() {
		return no;
	}

	@Override
	public String toString() {
		return "StuUser [no=" + no + ", toString()=" + super.toString() + "]";
	}

}

class UserReverseComparator implements Comparator<User> {

	@Override
	public int compare(User o1, User o2) {
		return o2.getAge() - o1.getAge();
	}

}

class StuUserComparator implements Comparator<StuUser> {

	@Override
	public int compare(StuUser o1, StuUser o2) {
		return o1.getNo().compareTo(o2.getNo());
	}

}

public class GenericMain {

	public static void main(String[] args) {
//		List<StuUser> stuList = new ArrayList<StuUser>();
//		stuList.add(new StuUser(21, "107"));
//		stuList.add(new StuUser(20, "91"));
//		stuList.add(new StuUser(21, "84"));
		UserReverseComparator userReverseComparator = new UserReverseComparator();
		StuUserComparator stuUserComparator = new StuUserComparator();
		User user = new User(22);
		StuUser stuUser = new StuUser(21, "97");
		StuUser stuUser1 = new StuUser(20, "91");
		System.out.println(user);
		System.out.println(stuUser);
		System.out.println(stuUser1);
		System.out.println(myCompare(stuUser, stuUser1, userReverseComparator));
		System.out.println(myCompare(stuUser, stuUser1, stuUserComparator));
	}
	
//	public static <stuCompare extends Comparable<StuUser>> StuUser max1(List<StuUser> stuList) {
//		StuUser max1 = stuList.get(0);
//		for(StuUser stu : stuList){
//			if(stu.compareTo(max1)>0)
//				max1 = stu;
//		}
//		return max1;
//	}
	
	public static <T> int myCompare(T o1, T o2, Comparator c) {
		int result = c.compare(o1, o2);
		return result;
	}
}